﻿using System;
using System.Linq;
using System.Text;
using Kaidou.Model;
using System.Data;
using System.Data.SqlClient;
using Kaidou.Util;
using System.Collections;
using Kaidou.Model;

namespace Kaidou.Persister
{
    public class MST_TraderPersister : Common
    {
        /**
	    * MST_Traderテーブルにレコードを挿入する。
	    * @param con コネクション
	    * @param trader 設置業者モデル
	    * @return void
	    */
        public void insertTrader(MstTrader M)
        {
            SqlDB db = new SqlDB();
            try
            {
                LogManager.info("MST_TraderPersister - insertTrader");
                String sql =
                "insert into mst_trader( "
                    // + "trader_seqno, "
                    + "trader_reg_no ,"
                    + "trader_name ,"
                    + "trader_kana ,"
                    + "trader_zip_no ,"
                    + "trader_pref_code ,"
                    + "trader_city ,"
                    + "trader_address ,"
                    + "trader_tel ,"
                    + "daihyo_name ,"
                    + "daihyo_kana ,"
                    + "union_code ,"
                    + "branch_code ,"
                    + "trader_sts ,"
                    + "reg_date ,"
                    + "upd_date ,"
                    + "upd_union_code ,"
                    + "upd_branch_code ,"
                    + "upd_func_id )"
                    + " values( "
                    // + "@trader_seqno,"
                    + "@trader_reg_no,"
                    + "@trader_name,"
                    + "@trader_kana,"
                    + "@trader_zip_no,"
                    + "@trader_pref_code,"
                    + "@trader_city,"
                    + "@trader_address,"
                    + "@trader_tel,"
                    + "@daihyo_name,"
                    + "@daihyo_kana,"
                    + "@union_code,"
                    + "@branch_code,"
                    + "@trader_sts,"
                    + "@reg_date,"
                    + "@upd_date,"
                    + "@upd_union_code,"
                    + "@upd_branch_code,"
                    + "@upd_func_id)";

                LogManager.info("MST_TraderPersister insertTrader -sql : " + sql);


                SqlParameter[] sqlParameter = {   
                                                //new SqlParameter("@trader_seqno",SqlDbType.Int),
                                                new SqlParameter("@upd_func_id",SqlDbType.VarChar,20),
                                                new SqlParameter("@trader_reg_no",SqlDbType.VarChar,8),
                                                new SqlParameter("@trader_name",SqlDbType.VarChar,128),
                                                new SqlParameter("@trader_kana",SqlDbType.VarChar,256),
                                                new SqlParameter("@trader_zip_no",SqlDbType.VarChar,7),
                                                new SqlParameter("@trader_pref_code",SqlDbType.SmallInt),
                                                new SqlParameter("@trader_city",SqlDbType.VarChar,256),
                                                new SqlParameter("@trader_address",SqlDbType.VarChar,256),
                                                new SqlParameter("@trader_tel",SqlDbType.VarChar,11),
                                                new SqlParameter("@daihyo_name",SqlDbType.VarChar,128),
                                                new SqlParameter("@daihyo_kana",SqlDbType.VarChar,128),
                                                new SqlParameter("@union_code",SqlDbType.VarChar,5),
                                                new SqlParameter("@branch_code",SqlDbType.SmallInt),
                                                new SqlParameter("@trader_sts",SqlDbType.VarChar,2),
                                                new SqlParameter("@reg_date",SqlDbType.DateTime),
                                                new SqlParameter("@upd_date",SqlDbType.DateTime),
                                                new SqlParameter("@upd_union_code",SqlDbType.VarChar,5),
                                                new SqlParameter("@upd_branch_code",SqlDbType.SmallInt)
                                                
                                               
                                              };

                sqlParameter[0].Value = M.UpdFuncId;
                sqlParameter[1].Value = M.TraderRegNo.Substring(0, 2) + "-" + M.TraderRegNo.Substring(2, 5);
                sqlParameter[2].Value = M.TraderName;
                sqlParameter[3].Value = M.TraderKana;
                sqlParameter[4].Value = M.TraderZipNo;
                sqlParameter[5].Value = M.TraderPrefCode;
                sqlParameter[6].Value = M.TraderCity;
                sqlParameter[7].Value = M.TraderAddress;
                sqlParameter[8].Value = M.TraderTel;
                sqlParameter[9].Value = M.DaihyoName;
                sqlParameter[10].Value = M.DaihyoKana;
                sqlParameter[11].Value = M.UnionCode;
                sqlParameter[12].Value = M.BranchCode;
                sqlParameter[13].Value = M.TraderSts;
                sqlParameter[14].Value = M.RegDate;
                sqlParameter[15].Value = M.UpdDate;
                sqlParameter[16].Value = M.UpdUnionCode;
                sqlParameter[17].Value = M.UpdBranchCode;
                //sqlParameter[18].Value = M.UpdFuncId;


                db.ExecuteCmd(sql.ToString(), sqlParameter);


            }
            catch (Exception e)
            {
                LogManager.error("MST_TraderPersister - insertTrader " + e.ToString());
            }
            finally
            {
                db.Close();
            }
        }

        /**
         * 指定された値のデータモデルのリストを取得する。
         * @param	con	コネクション
         * @param	model MST_Traderモデル
         * @reurn	Pager
         */
        public Pager search(MstTrader M, int pageNo, int pageSize)
        {

            ArrayList result = new ArrayList();

            StringBuilder sql = new StringBuilder();
            sql.Append("select * ");
           
            sql.Append("from ");

            StringBuilder where = new StringBuilder();
            where.Append(" where 1=1 ");

            if (M.TraderRegNo1 != null && M.TraderRegNo2 == null)
            {
                where.Append(" and left(trader_reg_no,2) = '" + M.TraderRegNo1 + "'");
            }

            if (M.TraderRegNo1 == null && M.TraderRegNo2 != null)
            {
                where.Append(" and right(trader_reg_no,5) = '" + M.TraderRegNo2 + "'");
            }

            if (M.TraderRegNo1 != null && M.TraderRegNo2 != null)
            {
                where.Append(" and trader_reg_no = '" + M.TraderRegNo1+"-"+M.TraderRegNo2 + "'");

            }

            /*
            if (M.TraderRegNo != null)
            {
                where.Append(" and trader_reg_no='" + M.TraderRegNo + "'");

            }
             */

            if (M.TraderName != null)
            {
                where.Append(" and trader_name like '%" + M.TraderName + "%'");

            }
            if (M.TraderKana != null)
            {
                where.Append(" and trader_kana like '%" + M.TraderKana + "%'");

            }
            if (M.TraderPrefCode != 0)
            {
                where.Append(" and trader_pref_code = " + M.TraderPrefCode);

            }

            where.Append(" and trader_sts !='" + MstTrader.STATUS_DELETE + "'");

           
            if (pageNo == 0)
            {
                pageNo = 1;
            }
            sql.Append(" (select TOP " + pageNo * pageSize + " *  from mst_trader " + where.ToString() + " order by trader_seqno asc ) T where T.trader_seqno not in " +
                "(select TOP " + (pageNo - 1) * pageSize + " trader_seqno from mst_trader " + where.ToString() + " order by trader_seqno asc ) order by T.trader_kana asc");

            SqlParameter[] sqlParameter = { };

            LogManager.info("MST_TraderPersister - search - sql:"+sql.ToString());

            SqlDB db = new SqlDB();

            try
            {


                SqlDataReader dataReader = db.GetDataCmd(sql.ToString(), sqlParameter);

                while (dataReader.Read())
                {

                    MstTrader model = new MstTrader();
                    model.TraderSeqno = (int)dataReader["trader_seqno"];
                    //trader.setTrader_seqno(rs.getInt("trader_seqno"));
                    model.TraderRegNo = (string)dataReader["trader_reg_no"];
                    model.TraderRegNo = model.TraderRegNo.Replace("-", "");
                    //trader.setTrader_reg_no(rs.getString("trader_reg_no"));
                    model.TraderName = (string)dataReader["trader_name"];
                    //trader.setTrader_name(rs.getString("trader_name"));
                    model.TraderKana = (string)dataReader["trader_kana"];
                    //trader.setTrader_kana(rs.getString("trader_kana"));
                    model.TraderZipNo = (string)dataReader["trader_zip_no"];
                    //trader.setTrader_zip_no(rs.getString("trader_zip_no"));
                    model.TraderPrefCode = (short)dataReader["trader_pref_code"];
                    //trader.setTrader_pref_code(rs.getInt("trader_pref_code"));
                    model.TraderCity = (string)dataReader["trader_city"];
                    //trader.setTrader_city(rs.getString("trader_city"));
                    model.TraderAddress = (string)dataReader["trader_address"];
                    //trader.setTrader_address(rs.getString("trader_address"));
                    model.TraderTel = (string)dataReader["trader_tel"];
                    //trader.setTrader_tel(rs.getString("trader_tel"));
                    model.DaihyoName = (string)dataReader["daihyo_name"];
                    //trader.setDaihyo_name(rs.getString("daihyo_name"));
                    model.DaihyoKana = (string)dataReader["daihyo_kana"];
                    //trader.setDaihyo_kana(rs.getString("daihyo_kana"));
                    model.UnionCode = (string)dataReader["union_code"];
                    //trader.setUnion_code(rs.getString("union_code"));
                    model.BranchCode = (short)dataReader["branch_code"];
                    //trader.setBranch_code(rs.getInt("branch_code"));
                    model.TraderSts = (string)dataReader["trader_sts"];
                    //trader.setTrader_sts(rs.getString("trader_sts"));
                    model.RegDate = (DateTime)dataReader["reg_date"];
                    //trader.setReg_date(rs.getTimestamp("reg_date"));
                    model.UpdDate = (DateTime)dataReader["upd_date"];
                    //trader.setUpd_date(rs.getTimestamp("upd_date"));
                    model.UpdUnionCode = (string)dataReader["upd_union_code"];
                    //trader.setUpd_union_code(rs.getString("upd_union_code"));
                    model.UpdBranchCode = (short)dataReader["upd_branch_code"];
                    //trader.setUpd_branch_code(rs.getInt("upd_branch_code"));
                    model.UpdFuncId = (string)dataReader["upd_func_id"];
                    //trader.setUpd_func_id(rs.getString("upd_func_id"));
                    result.Add(model);
                }




            }
            catch (Exception exx)
            {
                LogManager.error("MST_TraderPersister - search " + exx.Message);
            }
            finally
            {
                db.Close();
            }

            Pager pager = new Pager();
            pager.PageNo = pageNo;
            pager.PageSize = pageSize;
            pager.Total = getCount(where.ToString());
            pager.Pages = pager.Total % pageSize == 0 ? pager.Total / pageSize : pager.Total / pageSize + 1;
            pager.List = result;

            return pager;
        }

        /**
	    * 指定された値のデータモデルを取得する。
	    * @param trader_reg_no - 設置業者 登録証番号
	    * @return MST_Trader - 取得した設置業者のデータモデル
	    */
        public MstTrader getDetail(string trader_reg_no)
        {
            LogManager.info("MST_TraderPersister getDetail - in");
            MstTrader model = null;
            SqlDB db = new SqlDB();
            try
            {
                String sql =
                "select "
                    + "trader_seqno, "
                    + "trader_reg_no ,"
                    + "trader_name ,"
                    + "trader_kana ,"
                    + "trader_zip_no ,"
                    + "trader_pref_code ,"
                    + "trader_city ,"
                    + "trader_address ,"
                    + "trader_tel ,"
                    + "daihyo_name ,"
                    + "daihyo_kana ,"
                    + "union_code ,"
                    + "branch_code ,"
                    + "trader_sts ,"
                    + "reg_date ,"
                    + "upd_date ,"
                    + "upd_union_code ,"
                    + "upd_branch_code ,"
                    + "upd_func_id "
                    + " from mst_trader "
                    + " where "
                    + " trader_reg_no = @trader_reg_no ";


                SqlParameter[] sqlParameter = { new SqlParameter("@trader_reg_no", SqlDbType.VarChar, 8) };
                sqlParameter[0].Value = trader_reg_no.Substring(0, 2) + "-" + trader_reg_no.Substring(2, 5);
                SqlDataReader dataReader = db.GetDataCmd(sql.ToString(), sqlParameter);


                if (dataReader.Read())
                {
                    model = new MstTrader();
                    model.TraderSeqno = (int)dataReader["trader_seqno"];
                    //trader.setTrader_seqno(rs.getInt("trader_seqno"));
                    model.TraderRegNo = (string)dataReader["trader_reg_no"];
                    model.TraderRegNo = model.TraderRegNo.Replace("-", "");
                    //trader.setTrader_reg_no(rs.getString("trader_reg_no"));
                    model.TraderName = (string)dataReader["trader_name"];
                    //trader.setTrader_name(rs.getString("trader_name"));
                    model.TraderKana = (string)dataReader["trader_kana"];
                    //trader.setTrader_kana(rs.getString("trader_kana"));
                    model.TraderZipNo = (string)dataReader["trader_zip_no"];
                    //trader.setTrader_zip_no(rs.getString("trader_zip_no"));
                    model.TraderPrefCode = (short)dataReader["trader_pref_code"];
                    //trader.setTrader_pref_code(rs.getInt("trader_pref_code"));
                    model.TraderCity = (string)dataReader["trader_city"];
                    //trader.setTrader_city(rs.getString("trader_city"));
                    model.TraderAddress = (string)dataReader["trader_address"];
                    //trader.setTrader_address(rs.getString("trader_address"));
                    model.TraderTel = (string)dataReader["trader_tel"];
                    //trader.setTrader_tel(rs.getString("trader_tel"));
                    model.DaihyoName = (string)dataReader["daihyo_name"];
                    //trader.setDaihyo_name(rs.getString("daihyo_name"));
                    model.DaihyoKana = (string)dataReader["daihyo_kana"];
                    //trader.setDaihyo_kana(rs.getString("daihyo_kana"));
                    model.UnionCode = (string)dataReader["union_code"];
                    //trader.setUnion_code(rs.getString("union_code"));
                    model.BranchCode = (short)dataReader["branch_code"];
                    //trader.setBranch_code(rs.getInt("branch_code"));
                    model.TraderSts = (string)dataReader["trader_sts"];
                    //trader.setTrader_sts(rs.getString("trader_sts"));
                    model.RegDate = (DateTime)dataReader["reg_date"];
                    //trader.setReg_date(rs.getTimestamp("reg_date"));
                    model.UpdDate = (DateTime)dataReader["upd_date"];
                    //trader.setUpd_date(rs.getTimestamp("upd_date"));
                    model.UpdUnionCode = (string)dataReader["upd_union_code"];
                    //trader.setUpd_union_code(rs.getString("upd_union_code"));
                    model.UpdBranchCode = (short)dataReader["upd_branch_code"];
                    //trader.setUpd_branch_code(rs.getInt("upd_branch_code"));
                    model.UpdFuncId = (string)dataReader["upd_func_id"];
                    //trader.setUpd_func_id(rs.getString("upd_func_id"));
                }


            }
            catch
            {
                LogManager.error("MST_TraderPersister - getDetail");
            }
            finally
            {
                db.Close();
            }

            return model;

        }

        /**
         * 指定された値のデータモデルを取得する。
         * @param con コネクション
         * @param trader_seqno シーケンスNO
         * @return MST_Trader
         */
        public MstTrader getDetail(int trader_seqno)
        {
            LogManager.info("MST_TraderPersister getDetail - in");
            MstTrader model = null;
            SqlDB db = new SqlDB();
            try
            {
                String sql =
                "select "
                    + "trader_seqno, "
                    + "trader_reg_no ,"
                    + "trader_name ,"
                    + "trader_kana ,"
                    + "trader_zip_no ,"
                    + "trader_pref_code ,"
                    + "trader_city ,"
                    + "trader_address ,"
                    + "trader_tel ,"
                    + "daihyo_name ,"
                    + "daihyo_kana ,"
                    + "union_code ,"
                    + "branch_code ,"
                    + "trader_sts ,"
                    + "reg_date ,"
                    + "upd_date ,"
                    + "upd_union_code ,"
                    + "upd_branch_code ,"
                    + "upd_func_id "
                    + " from mst_trader "
                    + " where "
                    + " trader_seqno = @trader_seqno ";


                SqlParameter[] sqlParameter = { new SqlParameter("@trader_seqno", SqlDbType.Int) };
                sqlParameter[0].Value = trader_seqno;
                SqlDataReader dataReader = db.GetDataCmd(sql.ToString(), sqlParameter);


                if (dataReader.Read())
                {
                    model = new MstTrader();
                    model.TraderSeqno = (int)dataReader["trader_seqno"];
                    //trader.setTrader_seqno(rs.getInt("trader_seqno"));
                    model.TraderRegNo = (string)dataReader["trader_reg_no"];
                    model.TraderRegNo = model.TraderRegNo.Replace("-", "");
                    //trader.setTrader_reg_no(rs.getString("trader_reg_no"));
                    model.TraderName = (string)dataReader["trader_name"];
                    //trader.setTrader_name(rs.getString("trader_name"));
                    model.TraderKana = (string)dataReader["trader_kana"];
                    //trader.setTrader_kana(rs.getString("trader_kana"));
                    model.TraderZipNo = (string)dataReader["trader_zip_no"];
                    //trader.setTrader_zip_no(rs.getString("trader_zip_no"));
                    model.TraderPrefCode = (short)dataReader["trader_pref_code"];
                    //trader.setTrader_pref_code(rs.getInt("trader_pref_code"));
                    model.TraderCity = (string)dataReader["trader_city"];
                    //trader.setTrader_city(rs.getString("trader_city"));
                    model.TraderAddress = (string)dataReader["trader_address"];
                    //trader.setTrader_address(rs.getString("trader_address"));
                    model.TraderTel = (string)dataReader["trader_tel"];
                    //trader.setTrader_tel(rs.getString("trader_tel"));
                    model.DaihyoName = (string)dataReader["daihyo_name"];
                    //trader.setDaihyo_name(rs.getString("daihyo_name"));
                    model.DaihyoKana = (string)dataReader["daihyo_kana"];
                    //trader.setDaihyo_kana(rs.getString("daihyo_kana"));
                    model.UnionCode = (string)dataReader["union_code"];
                    //trader.setUnion_code(rs.getString("union_code"));
                    model.BranchCode = (short)dataReader["branch_code"];
                    //trader.setBranch_code(rs.getInt("branch_code"));
                    model.TraderSts = (string)dataReader["trader_sts"];
                    //trader.setTrader_sts(rs.getString("trader_sts"));
                    model.RegDate = (DateTime)dataReader["reg_date"];
                    //trader.setReg_date(rs.getTimestamp("reg_date"));
                    model.UpdDate = (DateTime)dataReader["upd_date"];
                    //trader.setUpd_date(rs.getTimestamp("upd_date"));
                    model.UpdUnionCode = (string)dataReader["upd_union_code"];
                    //trader.setUpd_union_code(rs.getString("upd_union_code"));
                    model.UpdBranchCode = (short)dataReader["upd_branch_code"];
                    //trader.setUpd_branch_code(rs.getInt("upd_branch_code"));
                    model.UpdFuncId = (string)dataReader["upd_func_id"];
                    //trader.setUpd_func_id(rs.getString("upd_func_id"));
                }


            }
            catch
            {
                LogManager.error("MST_TraderPersister - getDetail");
            }
            finally
            {
                db.Close();
            }

            return model;

        }


        /**
	    * MST_Traderテーブルからレコードを論理削除する。
	    * @param trader 設置業者モデル
	    */
        public void deleteTrader(MstTrader M)
        {
            LogManager.info("MST_TraderPersister - deleteTrader - in ");
            LogManager.info("MST_TraderPersister - deleteTrader - trader_seqno : " + M.TraderSeqno);

            SqlDB db = new SqlDB();
            try
            {
                String pssql = "update mst_trader set " + "trader_sts = @trader_sts, " + "upd_date = @upd_date, " + "upd_union_code = @upd_union_code, " + "upd_branch_code = @upd_branch_code " + "where " + "trader_seqno = @trader_seqno";



                SqlParameter[] sqlParameter = {   new SqlParameter("@trader_sts", SqlDbType.VarChar, 2),
                                                  new SqlParameter("@upd_date", SqlDbType.DateTime), 
                                                  new SqlParameter("@upd_union_code", SqlDbType.VarChar, 5),
                                                  new SqlParameter("@upd_branch_code", SqlDbType.SmallInt),
                                                  new SqlParameter("@trader_seqno", SqlDbType.Int)
                                                 
                                              };

                sqlParameter[0].Value = M.TraderSts;
                sqlParameter[1].Value = M.UpdDate;
                sqlParameter[2].Value = M.UpdUnionCode;
                sqlParameter[3].Value = M.UpdBranchCode;
                sqlParameter[4].Value = M.TraderSeqno;
                db.ExecuteCmd(pssql, sqlParameter);
                

            }
            catch (Exception e)
            {
                LogManager.error("MST_TraderPersister - deleteTrader " + e.Message);
            }
            finally
            {
                db.Close();
            }

        }

        /**
	    * MST_Traderテーブルにレコードを更新する。
	    * @param trader 設置業者モデル
	    */
        public void updateTrader(MstTrader M)
        {
            LogManager.info("MST_TraderPersister - updateTrader - in ");
            LogManager.info("MST_TraderPersister - updateTrader - trader_seqno : " + M.TraderSeqno);
            SqlDB db = new SqlDB();
            try
            {
                String sql =
            " update mst_trader set "
                + "trader_reg_no = @trader_reg_no ,"
                + "trader_name = @trader_name ,"
                + "trader_kana = @trader_kana ,"
                + "trader_zip_no = @trader_zip_no ,"
                + "trader_pref_code = @trader_pref_code ,"
                + "trader_city = @trader_city ,"
                + "trader_address = @trader_address ,"
                + "trader_tel = @trader_tel ,"
                + "daihyo_name = @daihyo_name ,"
                + "daihyo_kana = @daihyo_kana ,"
                + "union_code = @union_code ,"
                + "branch_code = @branch_code ,"
                + "upd_date = @upd_date ,"
                + "upd_union_code = @upd_union_code ,"
                + "upd_branch_code = @upd_branch_code ,"
                + "upd_func_id = @upd_func_id "
                + " where "
                + "trader_seqno = @trader_seqno ";



                SqlParameter[] sqlParameter = {   
                                                new SqlParameter("@trader_seqno",SqlDbType.Int),
                                                new SqlParameter("@trader_reg_no",SqlDbType.VarChar,8),
                                                new SqlParameter("@trader_name",SqlDbType.VarChar,128),
                                                new SqlParameter("@trader_kana",SqlDbType.VarChar,256),
                                                new SqlParameter("@trader_zip_no",SqlDbType.VarChar,7),
                                                new SqlParameter("@trader_pref_code",SqlDbType.SmallInt),
                                                new SqlParameter("@trader_city",SqlDbType.VarChar,256),
                                                new SqlParameter("@trader_address",SqlDbType.VarChar,256),
                                                new SqlParameter("@trader_tel",SqlDbType.VarChar,11),
                                                new SqlParameter("@daihyo_name",SqlDbType.VarChar,128),
                                                new SqlParameter("@daihyo_kana",SqlDbType.VarChar,128),
                                                new SqlParameter("@union_code",SqlDbType.VarChar,5),
                                                new SqlParameter("@branch_code",SqlDbType.SmallInt),
                                                //new SqlParameter("@trader_sts",SqlDbType.VarChar,2),
                                                //new SqlParameter("@reg_date",SqlDbType.DateTime),
                                                new SqlParameter("@upd_date",SqlDbType.DateTime),
                                                new SqlParameter("@upd_union_code",SqlDbType.VarChar,5),
                                                new SqlParameter("@upd_branch_code",SqlDbType.SmallInt),
                                                new SqlParameter("@upd_func_id",SqlDbType.VarChar,20)
                                              };

                sqlParameter[0].Value = M.TraderSeqno;
                sqlParameter[1].Value = M.TraderRegNo.Substring(0, 2) + "-" + M.TraderRegNo.Substring(2, 5);
                sqlParameter[2].Value = M.TraderName;
                sqlParameter[3].Value = M.TraderKana;
                sqlParameter[4].Value = M.TraderZipNo;
                sqlParameter[5].Value = M.TraderPrefCode;
                sqlParameter[6].Value = M.TraderCity;
                sqlParameter[7].Value = M.TraderAddress;
                sqlParameter[8].Value = M.TraderTel;
                sqlParameter[9].Value = M.DaihyoName;
                sqlParameter[10].Value = M.DaihyoKana;
                sqlParameter[11].Value = M.UnionCode;
                sqlParameter[12].Value = M.BranchCode;
                //sqlParameter[13].Value = M.TraderSts;
                //sqlParameter[13].Value = M.RegDate;
                sqlParameter[13].Value = M.UpdDate;
                sqlParameter[14].Value = M.UpdUnionCode;
                sqlParameter[15].Value = M.UpdBranchCode;
                sqlParameter[16].Value = M.UpdFuncId;

                db.ExecuteCmd(sql, sqlParameter);


            }
            catch (Exception e)
            {
                LogManager.error("MST_TraderPersister - updateTrader " + e.Message);
            }
            finally
            {
                db.Close();
            }

        }
        public int getCount(string where)
        {
            int count = 0;
            SqlDB db = new SqlDB();
            try
            {

                string sql = "select count(*) from mst_trader " + where;

                SqlParameter[] sqlParameter = { };
                SqlDataReader dataReader = db.GetDataCmd(sql, sqlParameter);
                if (dataReader.Read())
                {
                    count = (int)dataReader[0];
                }

            }
            catch
            {
                LogManager.error("MST_TraderPersister - getCount");
            }
            finally
            {
                db.Close();
            }

            return count;
        }
    
    }
}
